package loadsave.loadsaveobject;

import java.util.*;

import loadsave.Saver;

public class LoadSaveIndex extends LoadSaveObject {

	private List<Integer> indices;
	
	public LoadSaveIndex(String name, int ... newIndices) {
		super(name, "Index");
		indices = new ArrayList<Integer>();
		for (int i : newIndices) {
			this.indices.add(i);
		}
	}
	
	public LoadSaveIndex(int ... newIndices) {
		this("", newIndices);
	}
	
	@Override
	public Iterator<LoadSaveObject> getIterator() {
		return new Iterator<LoadSaveObject>() {

			@Override
			public void init() { }

			@Override
			public boolean hasNext() {
				return false;
			}

			@Override
			public void next() { }

			@Override
			public LoadSaveObject getCurrKey() {
				throw new RuntimeException("This operation is not supported for this Iterator");
			}

			@Override
			public LoadSaveObject getCurrVal() {
				throw new RuntimeException("This operation is not supported for this Iterator");
			}
			
		};
	}

	public void addIndex(int index) {
		indices.add(index);
	}
	
	public List<Integer> getIndices() {
		return indices;
	}
	
	@Override
	public void save(Saver s) {
		s.saveLoadSaveIndex(this);
	}

	@Override
	public String toString() {
		return "LoadSaveIndex: " + (getName().equals("") ? "":(getName() + " = ")) + Arrays.toString(indices.toArray()) + "\n";
	}
	
}

